﻿using System.Collections.Generic;
using System.Configuration;
using System.Web.Mvc;
using DevTrends.MvcDonutCaching;
using ECG.Common;
using ECG.DAL;
using ECG.WebUI.Models;

namespace ECG.WebUI.Controllers
{
    public class CategoryL1Controller : Controller
    {
        //
        // GET: /CategoryL1/

        public ActionResult Index(string categoryName = "", string categoryId = "", int page = 1, string discount = "", string brandId = "")
        {
            var itemCate = ProductCategoryDb.GetById(categoryId) ?? new ProductCategoryDto();
            var str = string.Empty;
            if (page != 1) str = " | trang " + page;
            ViewBag.strPage = str;
            ViewBag.listCateMapLink = ProductCategoryMapLinkDb.ShowBYCate(categoryId);
            return View(itemCate);
        }

        public PartialViewResult GetParentCate(string categoryId, int depth)
        {
            var data = new List<ProductCategoryParentCateDto>();
            if (depth == 1)
            {
                data = ProductCategoryDb.GetCategoryByParent(categoryId) ?? new List<ProductCategoryParentCateDto>();
            }
            return PartialView(data);
        }

        public PartialViewResult Adv1ByCategory(string category, int w, int o)
        {
            var bList = ProductCategoryBannerDb.GetListBannerByWidth(category, w, o) ?? new List<ProductCategoryBannerHomeDto>();
            return PartialView(bList);
        }
        //Babo new
        [DonutOutputCache(Duration = 36000, VaryByParam = "categoryId;page")]
        public ActionResult PromotionByCate(string categoryId = "", int page = 1)
        {
            var itemsPerPage = 4;//int.Parse(ConfigurationManager.AppSettings["ProductListByCateIdPageSize"]);
            var totalPage = 0;
            var model = ProductDb.GetProductPromotionByCateAndTotalView(page, itemsPerPage, ref totalPage, categoryId) ?? new List<ProductByCateTopListPagingDto>();
            ViewBag.PageInfo = new PageInfo { CurrentPage = page, PageSize = itemsPerPage, TotalPages = totalPage };
            ViewBag.CurrentPage = page;
            ViewBag.TotalPage = totalPage;
            ViewBag.Category = categoryId;
            return PartialView(model);
        }

        public PartialViewResult PromotionByCatePagging(string categoryId = "", int page = 1)
        {
            var itemsPerPage = 4;//int.Parse(ConfigurationManager.AppSettings["ProductListByCateIdPageSize"]);
            var totalPage = 0;
            var model = ProductDb.GetProductPromotionByCateAndTotalView(page, itemsPerPage, ref totalPage, categoryId) ?? new List<ProductByCateTopListPagingDto>();
            ViewBag.PageInfo = new PageInfo { CurrentPage = page, PageSize = itemsPerPage, TotalPages = totalPage };
            return PartialView(model);
        }

        [DonutOutputCache(Duration = 36000, VaryByParam = "categoryId")]
        public ActionResult ProductRateByCate(string categoryId = "")
        {
            ViewBag.Cate = categoryId;
            return PartialView();
        }

        public ActionResult ProductRateByCatePaging(string categoryId = "", int page = 1)
        {
            var itemsPerPage = 4;
            var totalPage = 0;
            var model = ProductDb.GetProductRateByCategoryId(page, itemsPerPage, ref totalPage, categoryId) ?? new List<ProductRateByCateTopListPagingDto>();
            ViewBag.PageInfo = new PageInfo { CurrentPage = page, PageSize = itemsPerPage, TotalPages = totalPage };
            ViewBag.CurrentPage = page;
            ViewBag.TotalPage = totalPage;
            ViewBag.Category = categoryId;
            return PartialView(model);
        }

        [DonutOutputCache(Duration = 36000, VaryByParam = "categoryId")]
        public ActionResult ProductCateWithTab(string categoryId = "")
        {
            ViewBag.Category = categoryId;
            return PartialView();
        }

        [DonutOutputCache(Duration = 36000, VaryByParam = "categoryId;page")]
        public PartialViewResult CategoryProductL1NewPagging(string categoryId = "", int page = 1)
        {
            var itemsPerPage = 4;//int.Parse(ConfigurationManager.AppSettings["ProductListByCateIdPageSize"]);
            var totalPage = 0;
            var model = ProductDb.GetAllProductByCategoryId(page, itemsPerPage, ref totalPage, categoryId) ?? new List<ProductRateByCateTopListPagingDto>();
            ViewBag.PageInfo = new PageInfo { CurrentPage = page, PageSize = itemsPerPage, TotalPages = totalPage };
            ViewBag.CurrentPage = page;
            ViewBag.TotalPage = totalPage;
            ViewBag.Category = categoryId;
            return PartialView(model);
        }
        [DonutOutputCache(Duration = 36000, VaryByParam = "categoryId;page")]
        public PartialViewResult CategoryProductL1BuyMostPagging(string categoryId = "", int page = 1)
        {
            var itemsPerPage = 4;//int.Parse(ConfigurationManager.AppSettings["ProductListByCateIdPageSize"]);
            var totalPage = 0;
            var model = ProductDb.GetAllProductByCategoryIdBuyMost(page, itemsPerPage, ref totalPage, categoryId) ?? new List<ProductByCateTopListPagingDto>();
            ViewBag.PageInfo = new PageInfo { CurrentPage = page, PageSize = itemsPerPage, TotalPages = totalPage };
            ViewBag.CurrentPage = page;
            ViewBag.TotalPage = totalPage;
            ViewBag.Category = categoryId;
            return PartialView(model);
        }
        // End product tcategoryL1 tab -------------------------

        [DonutOutputCache(Duration = 36000, VaryByParam = "categoryId;CateName")]
        public PartialViewResult GetProviderByCate(string categoryId,string CateName)
        {
            var data = ProviderDb.GetAllProviderByKeyWordAdmin(categoryId) ?? new List<ProviderListCateHomeDto>();
            ViewBag.categoryId = categoryId;
            ViewBag.CateName = CateName;
            return PartialView(data);
        }
        [DonutOutputCache(Duration = 36000, VaryByParam = "categoryId")]
        public ActionResult CateWithCateOther(string categoryId)
        {
            var bList = ProductCategoryBannerDb.GetListBannerByWidth(categoryId, 102, 0) ?? new List<ProductCategoryBannerHomeDto>();
            return PartialView(bList);
        }
    }
}
